<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui" template="template.xhtml">

	<ui:define name="main">
		<div class="header header_turma" />
		<h:form id="formConsultaTurma">
			<p:commandButton value="#{msgs.menu_cadastramento_turma}"
					action="cadastro_turma"
					 ajax="false" />
			
			<p:panel id="painelConsulta" header="#{msgs.turmas_cadastradas}"
				styleClass="painelConsulta">
				<p:dataTable var="turma" value="#{turmaBean.listaTurmas}"
					emptyMessage="#{msgs.pesquisa_vazia}#{msgs.dois_pontos}">
					<p:column style="width:150px;text-align:center"
						headerText="#{msgs.turma}#{msgs.dois_pontos}"
						filterBy="#{turma.idturma}" filterMatchMode="contains"
						footerText="#{msgs.contem}">
						<h:outputText value="#{turma.idturma}" />
					</p:column>
					<p:column style="width:150px;text-align:center"
						headerText="#{msgs.descricao_turma}#{msgs.dois_pontos}"
						filterBy="#{turma.descTurma}" filterMatchMode="contains"
						footerText="#{msgs.contem}">
						<h:outputText value="#{turma.descTurma}" styleClass="letra1" />
					</p:column>
					<p:column style="width:150px;text-align:center"
						headerText="#{msgs.periodo}#{msgs.dois_pontos}"
						filterBy="#{turma.fkPeriodo.descPeriodo}"
						filterMatchMode="contains" footerText="#{msgs.contem}">
						<h:outputText value="#{turma.fkPeriodo.descPeriodo}" />
					</p:column>
					<!--
					<p:column style="width:150px;text-align:center"
						headerText="#{msgs.nome_professor}#{msgs.dois_pontos}"
						filterBy="#{turma.fkProfessor.nome}" filterMatchMode="contains"
						footerText="#{msgs.contem}">
						 <h:outputText value="#{turma.fkProfessor.nome}"
							styleClass="letra1" /> 
					</p:column>
					-->
					<p:column style="width:150px;text-align:center"
						headerText="#{msgs.serie}#{msgs.dois_pontos}"
						filterBy="#{turma.fkSerie.descSerie}" filterMatchMode="contains"
						footerText="#{msgs.contem}">
						<h:outputText value="#{turma.fkSerie.descSerie}" />
					</p:column>
					
					<p:column style="width:150px;text-align:center"
						headerText="Qtd. Alunos#{msgs.dois_pontos}">
						<h:outputText value="#{turma.qtdAlunos}" />
					</p:column>
					<p:column style="width:50px;text-align:center">
						<p:commandButton image="ui-icon-pencil" title="Alterar"
							update="formCadastroTurma,modalTurma"
							oncomplete="modalTurma.show()"
							action="#{turmaBean.atualizarDadosTurma}">
							<f:setPropertyActionListener target="#{turmaBean.turma}"
								value="#{turma}" />
						</p:commandButton>
					</p:column>
					<p:column style="width:50px;text-align:center">
						<p:commandButton action="#{turmaBean.excluir}"
							image="ui-icon-close" title="Excluir"
							update="formConsultaTurma,painelConsulta">
							<f:setPropertyActionListener target="#{turmaBean.turma}"
								value="#{turma}" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
		</h:form>
		<p:dialog header="#{msgs.cadastro_professores}" widgetVar="modalTurma"
			modal="true" height="500" width="800" showEffect="highlight">

			<h:form id="formCadastroTurma" prependId="false">

				<p:ajaxStatus id="ajaxWaitTurma"
					style="position:absolute;margin-top:-17px;margin-left:43%;z-index:9;">
					<f:facet name="start">
						<h:graphicImage value="images/aguarde.gif" />
					</f:facet>
					<f:facet name="complete">
						<h:outputText value="" />
					</f:facet>
				</p:ajaxStatus>
				<p:message for="painel" />
				<h:panelGrid columns="2" width="90%">
					<h:panelGrid columns="2" width="60%">
						<h:outputLabel value="#{msgs.nome_turma}#{msgs.dois_pontos}" />
						<h:outputLabel value="#{msgs.curso}#{msgs.dois_pontos}" />
						<p:inputText id="nome_turma" value="#{turmaBean.turma.descTurma}"
							maxlength="45" required="true">
							<p:message for="nome_turma" />
						</p:inputText>
						<h:selectOneMenu value="#{turmaBean.idCurso}" id="curso">
							<f:selectItem itemLabel="#{msgs.selecione}" itemValue="0" />
							<f:selectItems value="#{turmaBean.selectItensCursos}" />
							<p:ajax listener="#{turmaBean.popularSerie}"
								update="series,panelSerie,id_periodo" process="@this" />
							<f:validator
								validatorId="br.com.pirralhos.view.validation.ComboValidator" />
							<p:message for="curso" />
						</h:selectOneMenu>
						<h:outputLabel value="#{msgs.serie}#{msgs.dois_pontos}" />
						<h:outputLabel value="#{msgs.periodo}#{msgs.dois_pontos}" />

						<h:selectOneMenu id="series" value="#{turmaBean.idSerie}"
							disabled="#{empty turmaBean.listaSeries}">
							<f:selectItem itemLabel="#{msgs.selecione}" itemValue="0" />
							<f:selectItems value="#{turmaBean.selectItensSeries}" />
							<f:validator
								validatorId="br.com.pirralhos.view.validation.ComboValidator" />
							<p:message for="series" />
							<p:ajax update="panelSerie" process="@this"
								listener="#{turmaBean.atualizarSerie}" />
							<f:validator
								validatorId="br.com.pirralhos.view.validation.ComboValidator" />
						</h:selectOneMenu>
						<h:selectOneMenu id="id_periodo" value="#{turmaBean.idPeriodo}"
							required="true" disabled="#{empty turmaBean.listaSeries}">
							<f:selectItem itemLabel="#{msgs.selecione}" itemValue="0" />
							<f:selectItems value="#{turmaBean.selectItensPeriodos}" />
							<p:message for="id_periodo" />
							<f:validator
								validatorId="br.com.pirralhos.view.validation.ComboValidator" />
						</h:selectOneMenu>

					</h:panelGrid>
					<h:panelGrid style="width:100%">
						<p:outputPanel id="panelSerie">
							<p:panel id="infoSerie"
								rendered="#{not empty turmaBean.serie.idserie}"
								header="#{msgs.informacoes_serie}">
								<h:panelGrid>
									<h:outputLabel
										value="Quantidade M&iacute;nima de professores:#{turmaBean.serie.qtdMinimaProfessores}" />
									<h:outputLabel
										value="Quantidade M&aacute;xima de professores:#{turmaBean.serie.qtdMaximaProfessores}" />
									<h:outputLabel
										value="Faixa de idade aluno: De #{turmaBean.serie.idadeMinimaMeses} meses a #{turmaBean.serie.idadeMaximaMeses} meses" />
								</h:panelGrid>
							</p:panel>
						</p:outputPanel>
					</h:panelGrid>
				</h:panelGrid>


				<h:outputLabel value="#{msgs.professores}#{msgs.dois_pontos}" />

				<p:pickList value="#{turmaBean.professores}" var="professor"
					itemValue="#{professor}" itemLabel="#{professor.nome}"
					converter="br.com.pirralhos.view.converter.ProfessorConverter"
					addLabel="#{msgs.adicionar}" addAllLabel="#{msgs.adicionar_todos}"
					removeLabel="#{msgs.remover}" id="painel"
					removeAllLabel="#{msgs.remover_todos}" />
				<h:inputHidden id="hiddenAlterouTurma"
					value="#{turmaBean.atualizou}" />
				<h:panelGrid styleClass="painelBotoes" columns="3">
					<p:commandButton value="#{msgs.botao_confirmar}"
						action="#{turmaBean.atualiza}"
						oncomplete="if(document.getElementById('hiddenAlterouTurma').value=='true'){modalTurma.hide();}"
						update="formCadastroTurma,formConsultaTurma" />
				</h:panelGrid>
			</h:form>
		</p:dialog>
	</ui:define>
</ui:composition>
